DISCUSSION
The
ATSUOffsetToPosition function determines the caret position(s) that correspond to an edge offset.
The user expects that pressing the mouse button correlates to the display of a caret in text. Your application should call the
ATSUOffsetToPosition function to find the caret position(s) corresponding to a mouse-down event.
To determine caret position(s), you must first pass the location of the mouse-down event to the function
ATSUPositionToOffset.
ATSUPositionToOffset passes back the edge offset (or offsets, if the hit occurs on a line direction boundary) from the beginning of the line where the hit occurred.
The offset passed back by
ATSUPositionToOffset is relative to the beginning of the line in which the hit occurred, not from the beginning of the text layout object's buffer. Because this offset is a relative position, you must transform the starting and ending pen locations of the caret(s) that are passed back by
ATSUOffsetToPosition before drawing them. The passed back carets do not need to be transformed to reflect angled and split caret appearances.
To do so, add the starting and ending caret coordinates to the coordinates of the origin of the line (in the current graphics port) in which the hit occurred. For example, if
ATSUOffsettoPosition passed back the starting and ending pen locations of (25,0), (25,25) in the
oMainCaret parameter (and the
oSecondCaret parameter contained the same coordinates, meaning that the caret was not split), you would add these to the position of the origin of the line in the graphics port. If the position of the line origin was at (50,50), then the starting and ending pen locations of the caret on the screen would be (75,50), (75,75).
To draw the caret, you can call the QuickDraw functions
MoveTo and
LineTo, or equivalent functions.